Skip to content

Conversation

@tzolov
Copy link
Contributor

@tzolov tzolov commented Mar 10, 2025

  • Implement the new ToolCallback.call(String, ToolContext) method in both Sync and Async MCP tool callbacks.
  • Since MCP tools don't support tool context, the implementation ignores the context parameter and delegates to the existing call(String) method. Added test to verify the behavior.

Resolves #2378

- Implement the new ToolCallback.call(String, ToolContext) method in both Sync and Async MCP tool callbacks.
- Since MCP tools don't support tool context, the implementation ignores the context parameter and
  delegates to the existing call(String) method. Added test to verify the behavior.

Resolves spring-projects#2378

Signed-off-by: Christian Tzolov <[email protected]>
}

@Override
public String call(String toolArguments, ToolContext toolContext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand why the default implementation of call(String, ToolContext) at ToolCallback is not enough as it handles null check and call(String) eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default implementation doesn't support non-empty ToolContext parameters and throws an exception. Here we override this to just ignore the tool-context parameter as it doesn't make sense for MCP

@ilayaperumalg ilayaperumalg merged commit 58ed5ea into spring-projects:main Mar 11, 2025
2 checks passed
@ilayaperumalg ilayaperumalg self-assigned this Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working MCP tool/function calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyncMcpToolCallback call fails with UnsupportedOperationException if ToolContext is set

2 participants